IF(MNN_BUILD_TRAIN)
  include_directories(${CMAKE_CURRENT_LIST_DIR}/source/grad)
  include_directories(${CMAKE_CURRENT_LIST_DIR}/source/optimizer)
  include_directories(${CMAKE_CURRENT_LIST_DIR}/source/parameters)
  include_directories(${CMAKE_CURRENT_LIST_DIR}/source/module)
  include_directories(${CMAKE_CURRENT_LIST_DIR}/source/transformer)
  include_directories(${CMAKE_CURRENT_LIST_DIR}/source/data)
  file(GLOB GRAD ${CMAKE_CURRENT_LIST_DIR}/source/grad/*)
  file(GLOB TRANSFORMER ${CMAKE_CURRENT_LIST_DIR}/source/transformer/*)
  file(GLOB MODULES ${CMAKE_CURRENT_LIST_DIR}/source/module/*)
  file(GLOB PARAMETER ${CMAKE_CURRENT_LIST_DIR}/source/parameters/*)
  file(GLOB OPTIMIZER ${CMAKE_CURRENT_LIST_DIR}/source/optimizer/*)
  file(GLOB DATALOADER ${CMAKE_CURRENT_LIST_DIR}/source/data/*)

  add_library(MNNTrain SHARED ${GRAD} ${BASIC_INCLUDE} ${PARAMETER} ${OPTIMIZER} ${MODULES} ${DATALOADER} ${TRANSFORMER})
  target_link_libraries(MNNTrain ${MNN_DEPS})
  IF(CMAKE_BUILD_TYPE MATCHES Release)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
  ENDIF()

  add_executable(transformer.out ${CMAKE_CURRENT_LIST_DIR}/source/exec/transformerExecution.cpp)
  target_link_libraries(transformer.out MNNTrain)

  add_executable(train.out ${CMAKE_CURRENT_LIST_DIR}/source/exec/train.cpp ${SCHEMA} ${BASIC_INCLUDE})
  target_link_libraries(train.out MNN)


  add_executable(rawDataTransform.out ${CMAKE_CURRENT_LIST_DIR}/source/exec/rawDataTransform.cpp ${SCHEMA} ${BASIC_INCLUDE})

  include_directories(../../3rd_party/imageHelper/)
  add_executable(dataTransformer.out ${CMAKE_CURRENT_LIST_DIR}/source/exec/dataTransformer.cpp ${SCHEMA} ${BASIC_INCLUDE})
  target_link_libraries(dataTransformer.out MNN)

  option(MNN_USE_OPENCV "Use opencv" OFF)

  file(GLOB DEMOSOURCE ${CMAKE_CURRENT_LIST_DIR}/source/demo/*)
  add_executable(runTrainDemo.out ${DEMOSOURCE} ${BASIC_INCLUDE})
  target_link_libraries(runTrainDemo.out MNNTrain)
  if (MNN_USE_OPENCV)
      set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_ORIGIN})
      set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_ORIGIN})
      find_package(OpenCV REQUIRED)
      include_directories(${OpenCV_INCLUDE_DIRS})
      add_definitions(-D MNN_USE_OPENCV)
      target_link_libraries(runTrainDemo.out ${OpenCV_LIBS})
  endif()
ENDIF()
